package com.laxia.util;


import java.util.Collection;
import java.util.Optional;

/**
 * @author weishuai
 */
public class OptionalUtil {

    public static <T extends Collection> Optional<T> ofEmpty(T value) {
        return (value == null || value.isEmpty()) ? Optional.empty() : Optional.of(value);
    }

    public static Optional<Object> ofNullable(Object value) {
        return Optional.ofNullable(value);
    }

    public static Optional<String> ofBlank(String value) {
        return StringUtil.isBlank(value) ? Optional.empty() : Optional.of(value);
    }

    public static Optional<Integer> ofPositive(Integer value) {
        return NumberUtil.isPositive(value) ? Optional.of(value) : Optional.empty();
    }

    public static Optional<Long> ofPositive(Long value) {
        return NumberUtil.isPositive(value) ? Optional.of(value) : Optional.empty();
    }
}
